﻿#include "ControlPanel.h"
#include "ui_ControlPanel.h"
#include "FITK_Component/FITKWidget/FITKTabWidget.h"
#include "TreeWidgetModel.h"
#include "TreeWidgetProp.h"
#include "TreeWidgetGroup.h"
#include "TreeWidgetLoad.h"
#include <QHeaderView>

namespace GUI
{

    TreeWidgetPage::TreeWidgetPage(QWidget* parent /*= nullptr*/)
        :Comp::FITKTreeWidget(parent)
    {
        //表头不可见
        this->header()->setVisible(false);
    }

    TreeWidgetPage::~TreeWidgetPage()
    {
    }
    
    GUI::TreeWidgetType TreeWidgetPage::getTreeWidgetType()
    {
        //错误值
        return PageNone;
    }

    ControlPanel::ControlPanel(QWidget* p) : Core::FITKWidget(p)
    {
        _ui = new Ui::ControlPanel;
        _ui->setupUi(this);

        Comp::FITKTabWidget* tab = new Comp::FITKTabWidget(Comp::FITKTabWidgetType::FITKTab_None, this);
        _ui->layout->addWidget(tab);
        //模型页
        _pages[PageModel] = new TreeWidgetModel(this);
        tab->addTab(_pages[PageModel], tr("Model"));
        //属性页
        _pages[PageProp] = new TreeWidgetProp(this);
        tab->addTab(_pages[PageProp], tr("Property"));
        // 分组页
        TreeWidgetGroupWin* gw = new TreeWidgetGroupWin(this);
        _pages[PageGroup] = gw->getTreeWidget();
        tab->addTab(gw, tr("Group"));
        //载荷页
        _pages[PageLoad] = new TreeWidgetLoad(this);
        tab->addTab(_pages[PageLoad], tr("Load"));

    }

    ControlPanel::~ControlPanel()
    {
        //释放分组
        QList<TreeWidgetPage*> ps = _pages.values();
        for (TreeWidgetPage* p : ps)
        {
            delete p;
        }
        _pages.clear();

        if (_ui) delete _ui;
    }

    GUI::TreeWidgetPage* ControlPanel::getTreeWidget(TreeWidgetType t)
    {
        //不存在则返回nullptr
        return _pages.value(t);
    }

}   


